<?php
function ajax_navi(){
	if( isset($_POST['action'])&& ($_POST['action'] == 'ajax_navi'))
	{
		global $wpdb,$DH_page_count_limit,$DH_page_range;
		$pagei='';
		$sql_rp='';
		$link='';
		$max_page='';
		
		//index页面
		if($_GET['page'])
		{
			$pagei=$_GET['page'];
			$begin = ($pagei-1)*$DH_page_count_limit;
			$sql_rp = "SELECT ID, post_title,post_content
				  FROM $wpdb->posts
				  WHERE post_type = 'post'
				  AND post_status = 'publish'
				  AND post_password = ''
				  ORDER BY ID DESC 
				  LIMIT $begin, $DH_page_count_limit;";
			$get_recent_post = $wpdb->get_results($sql_rp);
			$link=get_option("home").'/?page=';
			$max_page = get_option("dhstatic_max_page");			
		}
		//cat页面
		if($_GET['cpage'])
		{
			$pagei=$_GET['cpage'];
			$catid=$_GET['catid'];
			$begin = ($pagei-1)*$DH_page_count_limit;
			$get_recent_post = get_posts("category=$catid&offset=$begin&numberposts={$DH_page_count_limit}&post_status=publish&post_type=post");
			$link=get_option("home").'/?catid='.$catid.'&cpage=';
			$max_page = get_option("dhstatic_max_page_cat".$catid);				
		}
		//tag页面
		if($_GET['tpage'])
		{
			$pagei=$_GET['tpage'];
			$tagid=$_GET['tagid'];
			$begin = ($pagei-1)*$DH_page_count_limit;
			$tagvalue = get_tag_name($tagid);
			$get_recent_post = get_posts("tag=$tagvalue&offset=$begin&numberposts={$DH_page_count_limit}&post_status=publish&post_type=post");
			$link=get_option("home").'/?tagid='.$tagid.'&tpage=';
			$max_page = get_option("dhstatic_max_page_tag".$tagid);		
		}
		echo list_post($get_recent_post);
		//$max_page = get_option("dhstatic_max_page");
		$page_avi='<div class="page_navi">'.dh_pagenavi($DH_page_range,$max_page,$link,$pagei).'</div>';	
		echo $page_avi;		
		die();
	}
	else
	{
		return;
	}
}
add_action('init', 'ajax_navi');
?>